import jwt
import datetime
from django.conf import settings
key = settings.SECRET_KEY


class jwttool:
    def gettoken(self, user):
        # 设置过期时间
        # datetime.datetime.utcnow()是现在的时间+后面是过期时间
        user['exp'] = datetime.datetime.utcnow()+datetime.timedelta(hours=12)
        token = jwt.encode(user, key, algorithm='HS256')
        return token

    def parsetoken(self, token):
        user = jwt.decode(token, key, algorithms=['HS256'])
        return user


meansjwt = jwttool()

